<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <%@include file="/assets/publicjsp.jsp"%>
    <title>发布会议</title>
    <style>
        /*这个是这页面特有的，需要单独写出来*/
        .myTitle > input{
            float: right;
            margin-left: 15px;
        }

    </style>
</head>
<body>
<%@include file="../assets/header.jsp"%>

<div class="d-flex align-items-stretch">
    <!-- Sidebar Navigation-->
    <%@include file="../assets/side.jsp"%>
    <!-- Sidebar Navigation end-->
    <div class="page-content">
        <div class="page-header">
            <div class="container-fluid">
                <h2 class="h5 no-margin-bottom">发布会议</h2>
            </div>
        </div>

        <section class="no-padding-bottom">

            <div class="block-body">
                <form action="${pageContext.request.contextPath}/meeting/add" type="post">
                    <div class="form-group">
                        <label class="form-control-label">标题</label>
                        <input type="text" placeholder="会议标题" class="form-control" name="title" required>
                    </div>
                    <!--选择部门-->
                    <div class="form-group">
                        <label class="form-control-label">部门：</label>
                        <select class="selectpicker" data-live-search="true" name="deptId" id="depts"  required>

                        </select>
                        <input type="hidden" name="deptName" id="deptName" value="${deptMap.name}">
                        <label class="form-control-label">抄送人：</label>
                        <select class="selectpicker" data-live-search="true" multiple name="makeUser" id="users" required>

                        </select>
                    </div>
                    <!--开始时间-->
                    <div class="form-group">
                        <label class="form-control-label">开始时间</label>

                        <input type="text" class="form-control" id="startTime" name="startTime" data-date-format="yyyy-mm-dd hh:ii:ss" required>
                        <script>
                            $(function () {
                                $('#startTime').datetimepicker();
                            })
                        </script>
                    </div>
                    <!--结束时间-->
                    <div class="form-group">
                        <label class="form-control-label">结束时间</label>

                        <input type="text" class="form-control" id="endTime" name="endTime" data-date-format="yyyy-mm-dd hh:ii:ss" required>
                        <script>
                            $(function () {
                                $('#endTime').datetimepicker();
                            })
                        </script>
                    </div>
                    <div class="form-group">
                        <label class="form-control-label">会议内容</label>
                        <textarea class="form-control" rows="5" name="content" required></textarea>
                    </div>
                    <div class="text-center form-group">
                        <input type="submit" value="发布" class="btn btn-primary">
                        <input type="reset" value="清空" class="btn btn-info">
                    </div>
                </form>
            </div>
        </section>

        <%@include file="../assets/footer.jsp"%>
    </div>
</div>
<script>
$(function () {
    $.get("/dept/findAll?flag=1", function (all) {
        let deptHtml = "";
        deptHtml += "<option style='display: none'></option>";
        for (let dept of all) {
            deptHtml += "<option value=\"" + dept.deptId + "\">" + dept.deptName + "</option>";
        }
        $('#depts').html(deptHtml);
        $('#depts').selectpicker('refresh');
    });

    $("#depts").change(function () {
        // 设置部门名称
        $("#deptName").val($(this).find("option:selected").html());
        $.get("/dept/findUserByDeptId?id=" + $(this).val(), function (res){
            let userHtml = ""; for (let user of res) {
                userHtml += "<option value=\"" + user.id + "\">" + user.realName + "</option>"
            }
            $("#users").html(userHtml);
            // 刷新页面UI
            $('#users').selectpicker('refresh');
        });
    });
    $("#startTime").datetimepicker().on("changeDate",function (ev) {
        $('#endTime').datetimepicker('setStartDate', $(this).val());
    });

})
</script>
</body>
</html>